/*
 * @ProjectName: 综合安防
 * @Copyright:   2018 HangZhou Hikvision System Technology Co., Ltd. All Right Reserved.
 * @address:     http://www.hikvision.com
 * @date:        2018年01月29日 14:21
 * @description: 本内容仅限于杭州海康威视系统技术公有限司内部使用，禁止转发.
 */
package com.capsule.chapter.thread;

/**
 * <p>
 *
 * </p>
 *
 * @author xiachaoyang
 * @version V1.0
 * @date 2018年09月10日 14:08
 * @modificationHistory=========================逻辑或功能性重大变更记录
 * @modify By: {修改人} 2018年09月10日
 * @modify reason: {方法名}:{原因}
 * ...
 */
public class CountSyncService implements Runnable, CountInterface{

    private int loop;

    public CountSyncService(int loop) {
        this.loop = loop;
    }


    @Override
    public void count() {
        Constants.getInstance().syncAdd();
    }

    @Override
    public void insertThread(Thread thread) throws InterruptedException {
        //
    }

    /**
     * When an object implementing interface <code>Runnable</code> is used
     * to create a thread, starting the thread causes the object's
     * <code>run</code> method to be called in that separately executing
     * thread.
     * <p>
     * The general contract of the method <code>run</code> is that it may
     * take any action whatsoever.
     *
     * @see Thread#run()
     */
    @Override
    public void run() {
        for (int i = 0; i < loop; i++) {
            count();
        }
        System.out.println(String.format("%s >>> count is %d", Thread.currentThread().getName(), Constants.COUNT));
    }
}
